package main

import (
	"fmt"
	"os"
	"gogogo/pb"
	"github.com/golang/protobuf/proto"
)

func main () {
	person := pb.Person{
		Id: 1000,
		Name: "sierra",
		Email: "test@test.com",
		Phones: []*pb.Person_PhoneNumber{
			&pb.Person_PhoneNumber{"1024", pb.Person_HOME},
		},
	}
	data, err := proto.Marshal(&person); if err != nil {
		fmt.Printf("marshaling error: %+v", err)
	} else {
		fmt.Printf("%+v", data)
	}
	dataFile, err := os.OpenFile("person.data", os.O_RDWR|os.O_CREATE, 0755) // For read access.
	if err != nil {
		log.Fatal(err)
	}
	dataFile.Write(data)

	//newPerson := pb.Person{}
	//if err := proto.Unmarshal(data, &newPerson); err != nil {
	//	fmt.Printf("unmarshal error: %+v", err)
	//} else {
	//	fmt.Printf("data: %+v", newPerson)
	//}
}
